package com.example.crondemo.exception;

import com.example.crondemo.result.ResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author yanbl
 * @version V1.8
 * @Description: 自定义定时任务异常
 * @Date 2021/7/1 17:42
 */
@Data
@ApiModel("自定义定时任务异常")
public class TaskException extends RuntimeException {

    @ApiModelProperty(value = "异常状态码")
    private Integer code;

    /**
     * 通过状态码和错误消息创建异常
     * @param message
     * @param code
     */
    public TaskException(String message,Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型
     * @param resultCodeEnum
     */
    public TaskException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "TaskException{" +
                "code=" + code +
                '}';
    }
}
